package com.fireline.beauty.member;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import com.zgw.fireline.base.widgets.ControlUtil;
import org.eclipse.swt.widgets.Control;

/**
 * 付款差额处理
 * */
public class CeclDialog extends Dialog {

	protected int result; // 0 不做选择 1 付款欠款 ,2 付款优惠
	protected Shell shell;
	private String ce; // 差额

	/**
	 * Create the dialog.
	 * 
	 * @param parent
	 * @param style
	 */
	public CeclDialog(Shell parent, int style, String ce) {
		super(parent, style);
		setText("SWT Dialog");
		this.ce = ce;
	}

	/**
	 * Open the dialog.
	 * 
	 * @return the result
	 */
	public int open() {
		createContents();
		Display display = getParent().getDisplay();
		ControlUtil.centerShell(shell);
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setSize(369, 243);
		shell.setText("差额处理");

		Group group = new Group(shell, SWT.NONE);
		group.setText("差额处理选项");
		group.setBounds(10, 26, 334, 126);

		Label label = new Label(group, SWT.NONE);
		label.setBounds(37, 28, 267, 12);
		label.setText("付款金额小于交费金额请选择差额处理方式：");

		final Button buttonQk = new Button(group, SWT.RADIO);
		buttonQk.setSelection(true);
		buttonQk.setBounds(49, 59, 203, 16);
		buttonQk.setText("本次交费该会员欠款" + ce + "元");
		ControlUtil.setEnterToFocusMove(buttonQk);

		final Button buttonYh = new Button(group, SWT.RADIO);
		buttonYh.setText("本次交费对该会员优惠" + ce + "元");
		buttonYh.setBounds(49, 87, 203, 16);

		Button btnNewButton = new Button(shell, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				result = 0;
				shell.close();
			}
		});
		btnNewButton.setBounds(264, 168, 80, 22);
		btnNewButton.setText("退出");
		ControlUtil.setEnterToFocusMove(btnNewButton);

		Button btnNewButton_1 = new Button(shell, SWT.NONE);
		btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				result = buttonQk.getSelection() ? 1 : 2;
				shell.close();
			}
		});
		btnNewButton_1.setBounds(174, 168, 80, 22);
		btnNewButton_1.setText("确定");
		shell.setTabList(new Control[] { group, btnNewButton_1, btnNewButton });
	}
}
